<template>
  <div>
    <el-dialog :title="Aid == '' ? '添加排程' : '编辑排程'" :visible.sync="addEditIsDialog_c" @close="resetForm('formName')"
      width="800px">
      <el-form :model="ruleForm" :rules="rules" ref="formName" label-width="120px" class="demo-ruleForm"
        :class="{ 'form-rules-show': seeType }">
        <el-row>
          <el-col :span="12">
            <el-form-item label="选择排程模板：">
              <el-select v-model="ruleForm.modelId" placeholder="请选择排程模板" clearable>
                <el-option v-for="item in fishIdList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('formName')">取 消</el-button>
        <el-button class="btn-light-blue" @click="submitForm('formName')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script type="text/ecmascript-6">
import { getObjFishpond, saveObjFishpond } from "@/api/fishpond";
import { getCompanyInfoTree } from "@/api/company";
import {
  getConfigFishpondModelList, saveAutoTask,
} from "@/api/system";

export default {
  components: {},
  props: {
    addEditId: {
      type: String,
      default: "",
    },
    addEditStatus: {
      type: String,
      default: "add",
    },
    addEditIsDialog: {
      type: Boolean,
      default: false,
    },
    Aid: {
      type: String,
      default: "",
    },
    baseId: {
      default: "",
    },
    companyId: {
      default: "",

    }
  },
  data() {
    return {
      typeList: [
        { value: 0, label: "投料" },
        { value: 1, label: "换水" },
        { value: 2, label: "排污" },
        { value: 3, label: "增氧" }
      ],
      time: '',
      id: '',
      drainageList: [],
      fishIdList: [],
      watervalveList: [],
      ruleForm: {
        companyId: '',
        // 表单字段
        baseId: '',
        modelId: ''
      },
      groupList: [],
      rules: {
      },
      addEditIsDialog_c: false, // 弹窗是否显示
      seeType: false, // 是否禁用
      baseArray: [], // 基地集合
      companyArray: [], // 公司集合
      fishTypeArray: [], // 鱼类集合
      userType: "", // 用户类型（0超级管理员，1公司管理员）
      isShow: false,
      isShow2: false
      // baseId: ''
    };
  },
  mounted() {
    this.ruleForm.baseId = this.$route.query.baseId
    this.ruleForm.companyId = this.$route.query.companyId
    this.getgroupList()
  },
  watch: {


    addEditIsDialog(val) {
      this.addEditIsDialog_c = val;
      if (this.addEditIsDialog_c) {
        // 添加
        if (this.addEditStatus == "add") {
          this.ruleForm.id = -1;
          this.time = ''
          this.seeType = false;
        }
        // 编辑
        if (this.addEditStatus == "edit") {
          this.id = this.Aid
          this.ruleForm.id = this.Aid;
          this.seeType = false;
          this.getDetail();
        }
        // 查看
        if (this.addEditStatus == "see") {
          this.seeType = true;
          this.getDetail();
        }
        this.userType = Number(window.localStorage.getItem("userType"));
      }
    },
  },
  methods: {
    getgroupList() {
      getConfigFishpondModelList(this.ruleForm).then((res) => {
        if (res.code == 200) {
          this.fishIdList = res.data.data;
        }
      });
    },

    // 提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm);
          saveAutoTask(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: res.msg,
              });

              // 关闭弹窗
              this.$parent.closeAddEdit();
              // 刷新列表
              this.$parent.getFirstList();
            }
          });

          // this.ruleForm.startTime = String(this.ruleForm.startTime).slice(15, 21)
          // this.ruleForm.endTime = String(this.ruleForm.endTime).slice(15, 21)

        }
      });
    },
    // 取消
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$parent.closeAddEdit();
      this.isShow = false
      this.isShow2 = false;
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-input__icon {
  font-size: 0;
}

.demo-ruleForm {
  width: 95%;
  margin: 0 auto;
  padding-top: 10px;
}

.el-cascader {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
